package com.qq.BFMRSE.requestModule;

import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.methods.PostMethod;

import com.qq.BFMRSE.util.BFConstants;

public class loginModule {
	private String loginName;
	private String passWord;
	public loginModule(String loginName,String passWord){
		this.loginName=loginName;
		this.passWord=passWord;
	}
	public String getLoginName() {
		return loginName;
	}
	public void setLoginName(String loginName) {
		this.loginName = loginName;
	}
	public String getPassWord() {
		return passWord;
	}
	public void setPassWord(String passWord) {
		this.passWord = passWord;
	}
	public  boolean Login()
	{
		String url=BFConstants.URL+BFConstants.URLSPE+BFConstants.HANDLELOGIN;
		boolean isTrue=false;
		HttpClient httpClient=new HttpClient();
		PostMethod post=new PostMethod(url);
		post.setParameter("userName", loginName);
		post.setParameter("pwd", passWord);
		try {
			httpClient.executeMethod(post);
			int stateCode=post.getStatusCode();
			if(stateCode==200)
			{
				InputStream insStream=post.getResponseBodyAsStream();
				BufferedReader br=new BufferedReader(new InputStreamReader(insStream));
				String result="";
				String temp="";
				while((temp=br.readLine())!=null)
				{
					result+=temp;
				}
				isTrue=Boolean.parseBoolean(result);
			}
		} catch (HttpException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return isTrue;
	}


}
